/*
 * Lab07D.cpp - example returning by value, pointer or reference
 *
 *  Created on: Mar 25, 2014
 *      Author: Anthony Varghese
 */

#include <iostream>

using std::cin;
using std::cout;
using std::endl;


int returnSimpleInt(){
    return 10;
}

int returnLocalInt(){
    int i = 10;
    return i;
}

int& returnRefLocalInt(){
    int i = 10;
    return i;
}

int* returnPointerLocalInt(){
    int i = 10;
    return &i;
}

int* returnPointerHeapInt(){
    int* i = new int;
    *i = 10;
    return i;
}

int main(){
    cout << "CSIS 237 Lab 7 - Returning primitive data types" << endl;

    int rSI = returnSimpleInt();
    cout << "Using a simple int return, we get: " << rSI << endl;

    int rLI = returnLocalInt();
    cout << "Using a return of a local, we get: " << rLI << endl;

    int& rRI = returnRefLocalInt();
    cout << "Using a return of a local, we get: " << rRI << endl;

    int* rPI1 = returnPointerLocalInt();
//    int* rPI2 = returnPointerLocalInt();
    cout << "Using a return of a pointer to a local, we get: " << *rPI1 << endl;
//    cout << "Using a return of a pointer to a local, we get: " << *rPI2 << endl;

    int* rHI = returnPointerHeapInt();
    cout << "Using a return of a pointer to a location in heap, we get: " << *rHI << endl;

    cout << "... done" << endl;
}
